package com.useeinfo.oa.modules.wuHanCommon.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.CommonSugar;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.framework.sugar.tools.TimeCover;
import com.useeinfo.oa.modules.base.entity.Organization;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * 报警具体数据
 */
@Entity
@Table(name = "wuhan_warning_detail")
public class WarningDetail extends SuperClassEntity<WarningDetail> {

    /**
     * 所属警告
     */
    @ManyToOne
    @JoinColumn(name = "warning_id")
    private Warning warning;
    /**
     * 所属点位
     */
    @ManyToOne
    @JoinColumn(name = "point_id")
    private WuHanPoint wuHanPoint;

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = new JSONObject();

        Warning warning = CommonSugar.getTypedDefault(getWarning(), new Warning());
        WuHanPoint wuHanPoint = CommonSugar.getTypedDefault(getWuHanPoint(), new WuHanPoint());

        jsonObject.put("id", CommonSugar.getTypedDefault(getId(), 0L));
        jsonObject.put("pointName", CommonSugar.getTypedDefault(wuHanPoint.getRemark(), ""));
        jsonObject.put("system", CommonSugar.getTypedDefault(warning.getSystem(), ""));
        jsonObject.put("content", CommonSugar.getTypedDefault(warning.getContent(), ""));
        jsonObject.put("startTime", CommonSugar.getTypedDefault(DateTimeUtils.formatDateToStringWithTime(warning.getStartTime()), ""));
        jsonObject.put("createDate", CommonSugar.getTypedDefault(DateTimeUtils.formatDateToStringWithTime(getCreateDate()), ""));
        return jsonObject;
    }

    public JSONObject toJSONObjectView() {
        JSONObject jsonObject = new JSONObject();

        WuHanPoint wuHanPoint = CommonSugar.getTypedDefault(getWuHanPoint(), new WuHanPoint());
        Warning warning = CommonSugar.getTypedDefault(getWarning(), new Warning());
        Organization organization = CommonSugar.getTypedDefault(warning.getOrganization(), new Organization());

        jsonObject.put("id", CommonSugar.getTypedDefault(getId(), 0L));
        jsonObject.put("pointName", CommonSugar.getTypedDefault(wuHanPoint.getRemark(), ""));
        jsonObject.put("content", CommonSugar.getTypedDefault(warning.getContent(), ""));
        jsonObject.put("level", CommonSugar.getTypedDefault(warning.getLevel(), ""));
        jsonObject.put("system", CommonSugar.getTypedDefault(warning.getSystem(), ""));
        jsonObject.put("bindPointValue", CommonSugar.getTypedDefault(warning.getBindPointValue(), ""));
        jsonObject.put("infoDetail", CommonSugar.getTypedDefault(warning.getInfoDetail(), ""));
        jsonObject.put("lastSeconds", TimeCover.formatDateTime(CommonSugar.getTypedDefault(warning.getLastSeconds(), 0L)));
        jsonObject.put("department", CommonSugar.getTypedDefault(organization.getOrganizationName(), ""));
        return jsonObject;
    }

    public WarningDetail() {
    }

    public WarningDetail(WuHanPoint wuHanPoint) {
        this.wuHanPoint = wuHanPoint;
    }

    public WuHanPoint getWuHanPoint() {
        return wuHanPoint;
    }

    public void setWuHanPoint(WuHanPoint wuHanPoint) {
        this.wuHanPoint = wuHanPoint;
    }

    public Warning getWarning() {
        return warning;
    }

    public void setWarning(Warning warning) {
        this.warning = warning;
    }
}
